home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 3
/
Cream of the Crop 3.iso
/
comm
/
wnos5src.zip
/
IPDUMP.C
< prev
next >
Wrap
Text File
|
1993-10-14
|
2KB
|
91 lines
#include <stdio.h>
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "internet.h"
#include "ip.h"
#include "trace.h"
#include "netuser.h"
void
ip_dump(FILE *fp,struct mbuf **bpp,int check)
{
struct ip ip;
int16 ip_len, length, csum = 0;
if(bpp == NULLBUFP || *bpp == NULLBUF) {
return;
}
/* Sneak peek at IP header and find length */
if(((ip_len = ((*bpp)->data[0] & 0xf) << 2)) < IPLEN) {
trprintf(fp,"IP: bad header\n");
return;
}
if(check) {
csum = cksum(NULLHEADER,*bpp,ip_len);
}
ntohip(&ip,bpp); /* Can't fail, we've already checked ihl */
/* Trim data segment if necessary. */
length = ip.length - ip_len; /* Length of data portion */
trim_mbuf(bpp,length);
trprintf(fp,"IP: len %u %s->",ip.length,inet_ntoa(ip.source));
trprintf(fp,"%s ihl %u ttl %u",inet_ntoa(ip.dest),ip_len,uchar(ip.ttl));
if(ip.tos != 0) {
trprintf(fp," tos %u",uchar(ip.tos));
}
if(ip.offset != 0 || ip.flags.mf) {
trprintf(fp," id %u offs %u",ip.id,ip.offset);
}
if(ip.flags.df) {
trprintf(fp," DF");
}
if(ip.flags.mf) {
trprintf(fp," MF");
check = 0; /* Bypass host-level checksum verify */
}
if(ip.flags.congest) {
trprintf(fp," CE");
}
if(csum) {
trprintf(fp," CHECKSUM ERROR (%u)",csum);
}
if(ip.offset != 0) {
trprintf(fp,"\n");
} else {
trprintf(fp," prot ");
switch(uchar(ip.protocol)){
case IP_PTCL:
trprintf(fp,"IP\n");
ip_dump(fp,bpp,check);
break;
case TCP_PTCL:
trprintf(fp,"TCP\n");
tcp_dump(fp,bpp,ip.source,ip.dest,check);
break;
#ifdef AX25
case AX25_PTCL:
trprintf(fp,"AX25\n");
ax25_dump(fp,bpp,check);
break;
#endif
#ifdef UDP
case UDP_PTCL:
trprintf(fp,"UDP\n");
udp_dump(fp,bpp,ip.source,ip.dest,check);
break;
#endif
case ICMP_PTCL:
trprintf(fp,"ICMP\n");
icmp_dump(fp,bpp,ip.source,ip.dest,check);
break;
default:
trprintf(fp,"%u\n",uchar(ip.protocol));
break;
}
}
return;
}